package com.example.springboot_jdk8.service.impl;

import com.example.springboot_jdk8.entity.MdmOrg;
import com.example.springboot_jdk8.enums.PullDataConfigEnum;
import com.example.springboot_jdk8.service.IPullData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 门面模式
 * 封装对外统一操作
 * 四类型+两两排列组合
 * 全量拉取 组织 + 全量数据转换 组织
 * 增量数据拉取 用户+ 增量数据转换 用户
 * 依此类推
 */
@Service
public class PullDataFaced {

    @Autowired
    private List<IPullData> pullDatas;

    /**
     * 门面- 全量拉取组织,全量转换组织
     * @param pullDataModel 模式 - 全量/增量
     * @return
     */
    public List<MdmOrg> pullOrgs(PullDataConfigEnum pullDataModel){
        return pullDatas.stream()
                .filter(iPullData -> iPullData.supportPullDataType(PullDataConfigEnum.ORG) && iPullData.supportPullDataModel(pullDataModel))
                .findFirst().orElseThrow(()-> new RuntimeException("未匹配到策略"))
                .pullData();
    }



    /**
     * 门面- 全量拉取用户,全量转换用户
     * @param pullDataModel 模式 - 全量/增量
     * @return
     */
    public List<MdmOrg> pullUsers(PullDataConfigEnum pullDataModel){
        return pullDatas.stream()
                .filter(iPullData -> iPullData.supportPullDataType(PullDataConfigEnum.USER) && iPullData.supportPullDataModel(pullDataModel))
                .findFirst().orElseThrow(()-> new RuntimeException("未匹配到策略"))
                .pullData();
    }
}
